<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue路由开发-参数传递</title>
</head>
<body>
    <div id="app"> 
        <h1>{{msg}}</h1>
        <router-link to="/t1?id=1&name=张三" tag="button">跳转到t1组件</router-link>
        <router-link to="/t2/2/迪迦" tag="button">跳转到t2组件</router-link>
        <!-- 路由匹配到的组件会被渲染在这里 -->
        <router-view></router-view>
    </div>
</body>
<template id="t1">
    <div>
        <h1>组件1</h1>
        <!-- 获取路由参数 -->
         <p>id: {{id}}</p>
         <p>name: {{name}}</p>
    </div>
</template>
<template id="t2">
    <div>
        <h1>组件2</h1>
        <!-- 获取路由参数 -->
         <p>id: {{id}}</p>
         <p>name: {{name}}</p>
    </div>
</template>
</html>
<script type="module">
    import {} from './js/vue.js'
    import {} from './js/vue-router.js'
    let t1 = {
        template: '#t1',
        data () {
            return {
                id: this.$route.query.id,
                name: this.$route.query.name
            }
        }
    }
    let t2 = {
        template: '#t2',
        data () {
            return {
                id: this.$route.params.id,
                name: this.$route.params.name
            }
        }

}
    //创建路由规则
    let routes = [
        {path: '/t1', component: t1},
        {path: '/t2/:id/:name', component: t2}
    ]
    //创建路由实例
    let router = new VueRouter({
        routes
    })


    let app = new Vue({
        el: '#app',
        data: {
            msg: 'vue路由开发-参数传递'
        },
        router //挂载路由实例
    })
</script>